
#* * * * * /path-of-this-script/monitor.pl

#!/usr/bin/perl

sub send_sms{
    my $dongkai="13456782967";
    my $xiyu="13567125405";

    my $msg_1="drc_mysql_pidfile_doesnt_exist";
    my $msg_2="drc_mysql_process_has_beend_killed";

    my $sms_1_dongkai = "curl -s -G --connect-timeout 10 -d level=1 -d user=dba -d password=hello123 -d receiver=$dongkai -d message=$msg_1 'http://172.19.19.228/cgi-bin/add_sms.pl'";
    my $sms_1_xiyu = "curl -s -G --connect-timeout 10 -d level=1 -d user=dba -d password=hello123 -d receiver=$xiyu -d message=$msg_1 'http://172.19.19.228/cgi-bin/add_sms.pl'";

    my $sms_2_dongkai = "curl -s -G --connect-timeout 10 -d level=1 -d user=dba -d password=hello123 -d receiver=$dongkai -d message=$msg_2 'http://172.19.19.228/cgi-bin/add_sms.pl'";
    my $sms_2_xiyu = "curl -s -G --connect-timeout 10 -d level=1 -d user=dba -d password=hello123 -d receiver=$xiyu -d message=$msg_2 'http://172.19.19.228/cgi-bin/add_sms.pl'";

    if(@_ eq "1"){
        system($sms_1_dongkai) == 0 or die "failed: $?";
        system($sms_1_xiyu) == 0 or die "failed: $?";
    }
    else{   
        system($sms_2_dongkai) == 0 or die "failed: $?";
        system($sms_2_xiyu) == 0 or die "failed: $?";
    }
}


$pid_file = "/u01/drc_mysql_data/repsync.pid";
sysopen(handle,$pid_file,O_RDONLY) or &send_sms(1);

while(<handle>){
    if( -e "/proc/$_") {
    }
    else {
        &send_sms(2);
    }
}

